import axios from "axios";
let env = process.env.NODE_ENV || 'development'
let baseURL = ''
//根据环境配置基本路径
switch (env) {
  case 'development':
    baseURL = 'http://127.0.0.1:8888/api/private/v1/'
    break;
  case 'production':
    baseURL = 'http://127.0.0.1:8888/api/private/v1/'
    break;
  default:
    break;
}
axios.defaults.baseURL = baseURL
//在cors跨域中,允许携带资源凭证,后端需要设置好credentials为true
//axios.defaults.withCredentials = true
//通过axios请求拦截器给请求头添加token,保证拥有获取数据的权限
axios.interceptors.request.use(config =>{
  //给请求头对象,添加token验证的Authorization字段
  config.headers.Authorization = sessionStorage.getItem('token')
  return config
})
export default axios
